package com.iwayin.web.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 工具处理类 ajax：返回json
 * 
 * @author xiaobo.feng<xiaobo.feng@foxmail.com>
 * 
 *         2011-8-9
 */
@SuppressWarnings("unchecked")
public class AjaxResult {

	private Integer resultCode;
	private String message;
	private Map resultMap;

	public final static Integer OK = 1;
	public final static Integer FAILURE = 0;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Integer getResultCode() {
		return resultCode;
	}

	public void setResultCode(Integer resultCode) {
		this.resultCode = resultCode;
	}

	public boolean isOK() {
		if (this.resultCode.equals(AjaxResult.OK)) {
			return true;
		} else {
			return false;
		}
	}

	public Map getResultMap() {
		return resultMap;
	}

	public void setResultMap(Map resultMap) {
		this.resultMap = resultMap;
	}

	public static AjaxResult succResult() {
		AjaxResult r = new AjaxResult();
		r.setResultCode(AjaxResult.OK);
		return r;
	}
	
	public static AjaxResult succResultAndInitMap() {
		AjaxResult r = new AjaxResult();
		r.setResultCode(AjaxResult.OK);
		r.setResultMap(new HashMap());
		return r;
	}

	public static AjaxResult errorResult(String message) {
		AjaxResult r = new AjaxResult();
		r.setResultCode(AjaxResult.FAILURE);
		r.setMessage(message);
		return r;
	}

	public static AjaxResult commonResult(String message) {
		AjaxResult r = new AjaxResult();
		r.setResultCode(AjaxResult.OK);
		r.setMessage(message);
		return r;
	}
}
